<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>

</html>
<script>
  function Myapp(func, ...args) {
    //创建一个对象，因为对象就是一个实例
    let obj = {}
    //修改func的this向与obj的this指向一样
    let result = func.call(obj, ...args)
    if (typeof result === 'object' || typeof result === 'function') {
      return result
    }
    //将obj的__proto__与func的原型相等
    obj.__proto__ = func.prototype
    return obj
  }

  function Dgg(age) {
    this.age = age
  }

  Dgg.prototype.say = function () {
    console.log('sulli');
  }
  const agg = new Myapp(Dgg, 2)
  console.log(agg.age);
  agg.say()
</script>
